//
//  LXLMultiPhotoLayout.m
//  FZAH
//
//  Created by 李小龙 on 17/3/27.
//  Copyright © 2017年 zdqk. All rights reserved.
//

#import "LXLMultiPhotoLayout.h"

@implementation LXLMultiPhotoLayout
//必须重写的三个方法
-(void)prepareLayout
{
    [super prepareLayout];
    attributesArray = [[NSMutableArray alloc]init];
    
    //获得当前section中有几个item
    NSInteger count = [self.collectionView numberOfItemsInSection:0];
    for (int j = 0; j < count; j++) {
        //获得要修改的属性的indexPath
        NSIndexPath *indexPath = [NSIndexPath indexPathForItem:j inSection:0];
        UICollectionViewLayoutAttributes *att = [UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:indexPath];
        //修改属性
        att.frame = CGRectMake(self.collectionView.frame.size.width/3 * (j%3), self.collectionView.frame.size.width/3 * (j/3), self.collectionView.frame.size.width/3, self.collectionView.frame.size.width/3);
        //修改完成后放到数组中
        [attributesArray addObject:att];
    }
    
}
-(UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return [attributesArray objectAtIndex:indexPath.row];
}
-(NSArray *)layoutAttributesForElementsInRect:(CGRect)rect
{
    return attributesArray;
}
//滚动视图大小
-(CGSize)collectionViewContentSize
{
    NSInteger count = [self.collectionView numberOfItemsInSection:0];
    CGSize size = CGSizeMake(0, (count/3+1)*(self.collectionView.frame.size.width/3));
    if (size.height <= ScreenHeight) {
        size.height = ScreenHeight+5;
    }
    return size;
}

@end
